package Classes.GameViews.ViewDisplayers.MapTargets.MapMoveTargets// ActionScript file
{
	import Classes.GameDatas.GD_MapGrid;
	import Classes.GameDatas.GameData;
	import Classes.GameUtils.GU_IsoUtils;
	import Classes.GameViews.GV_Map;
	import Classes.GameViews.ViewDisplayers.MapTargets.MapTarget;
	
	import flash.geom.Point;

	/**
	 *地图移动对象类 
	 * @author 葛增文
	 * 
	 */	
	public class MapMoveTarget extends MapTarget
	{
		public static const MAXSPEED:int=480;/*地图移动对象最大速度*/
		private var _moveDir:int;/*移动方向 0:没有移动  1:左   2:左上  3:上  4:右上  5:右  6:右下  7:下  8:左下*/
		private var _speed:int;/*地图移动对象速度*/
		private var _positionCount:int=0;/*移动计数器*/
		private var _nowCountLimit:int;/*当前移动计数触发值*/
		private var _moveConditionsAry:Array;/*移动条件数组*/
		private var _actionLocked:Boolean;/*行动锁定*/
		public function MapMoveTarget(gd:GameData):void
		{
			super(gd);
			this.init();
		}
		
		private function init():void
		{
			this._moveConditionsAry=new Array;
			//this.scaleX=0.5;
			//this.scaleY=0.5;
		}
		
		/**
		 *移动更新 
		 * 
		 */		
		public function update():void
		{
			if(this.moveDir && !this.actionLocked)
			{
				this.positionCount+=1;
				this.updatePosition();
				if(this.positionCount==this.nowCountLimit)
				{
					this.moveOver();
				}
			}
		}
		
		/**
		 *位置更新 
		 * 
		 */		
		public function updatePosition():void
		{
			if(null==this.mapGrid)return;
			var extraValue:Number=GV_Map.instance.gridSize*(1-this.positionCount/this.nowCountLimit);
			var isoPoint:Point=new Point(this.mapGrid.atx*GV_Map.instance.gridSize,this.mapGrid.aty*GV_Map.instance.gridSize);
			switch(this.moveDir)
			{
				case 1:
					isoPoint.x+=extraValue;
					isoPoint.y-=extraValue;
					break;
				case 2:
					isoPoint.x+=extraValue;
					break;
				case 3:
					isoPoint.x+=extraValue;
					isoPoint.y+=extraValue;
					break;
				case 4:
					isoPoint.y+=extraValue;
					break;
				case 5:
					isoPoint.x-=extraValue;
					isoPoint.y+=extraValue;
					break;
				case 6:
					isoPoint.x-=extraValue;
					break;
				case 7:
					isoPoint.x-=extraValue;
					isoPoint.y-=extraValue;
					break;
				case 8:
					isoPoint.y-=extraValue;
					break;
			}
			var screenPoint:Point=GU_IsoUtils.isoToScreen(isoPoint);
			this.x=screenPoint.x;
			this.y=screenPoint.y;
		}
		
		/**
		 *当前移动结束处理 
		 * 
		 */		
		protected function moveOver():void
		{
			this.positionCount=0;
			this.moveDir=0;
			this.nextStep();
		}
		
		/**
		 *下一步行动 
		 * 
		 */		
		protected function nextStep():void
		{
			
		}
		
		/**
		 *开始移动 
		 * @param mapGrid 目标地图格
		 * 
		 */		
		public function beginMoveTo(toGrid:GD_MapGrid):void
		{
//			this.nowCountLimit=MAXSPEED-this.speed+1;
			this.nowCountLimit=MAXSPEED/this.speed;
			if(this.moveDir==1 || this.moveDir==7)
			{
				this.nowCountLimit=this.nowCountLimit*2;
			}
			this.moveDir=this.mapGrid.getDir(toGrid);
			this.mapGrid=toGrid;
		}
		
		override public function setPosition(mapGrid:GD_MapGrid):void
		{
			super.setPosition(mapGrid);
			this.positionCount=0;
			this.moveDir=0;
		}
		
		protected function transformDir(target:Object):Object
		{
			switch(target)
			{
				case 1:
					return "left";
				case 2:
					return "leftUp";
				case 3:
					return "up";
				case 4:
					return "rightUp";
				case 5:
					return "right";
				case 6:
					return "rightDown";
				case 7:
					return "down";
				case 8:
					return "leftDown";
				case "left":
					return 1;
				case "leftUp":
					return 2;
				case "up":
					return 3;
				case "rightUp":
					return 4;
				case "right":
					return 5;
				case "rightDown":
					return 6;
				case "down":
					return 7;
				case "leftDown":
					return 8;
			}
			return null;
		}

		/*getter & setter*/
		public function get moveDir():int
		{
			return _moveDir;
		}

		public function set moveDir(value:int):void
		{
			_moveDir = value;
		}

		public function get speed():int
		{
			return _speed;
		}

		public function set speed(value:int):void
		{
			_speed = value;
			if(this.speed>MAXSPEED)this.speed=MAXSPEED;
		}

		/**
		 *  移动计数器 
		 * @return 
		 */		
		public function get positionCount():int
		{
			return _positionCount;
		}

		public function set positionCount(value:int):void
		{
			_positionCount = value;
		}

		/**
		 * 移动数组 
		 * @return 
		 * 
		 */		
		public function get moveConditionsAry():Array
		{
			return _moveConditionsAry;
		}

		public function set moveConditionsAry(value:Array):void
		{
			_moveConditionsAry = value;
		}

		public function get actionLocked():Boolean
		{
			return _actionLocked;
		}

		public function set actionLocked(value:Boolean):void
		{
			_actionLocked = value;
		}

		/**
		 * 当前移动计数触发值 
		 * @return 
		 * 
		 */		
		public function get nowCountLimit():int
		{
			return _nowCountLimit;
		}

		public function set nowCountLimit(value:int):void
		{
			_nowCountLimit = value;
		}
		
		/**
		 *合法位置条件数组 
		 * @return 
		 * 
		 */		
		public function get correctPositionConditionsAry():Array
		{
			return new Array;
		}
		
		/**
		 *重置位置条件数组 
		 * @return 
		 * 
		 */		
		public function get resetPositionConditionsAry():Array
		{
			return new Array;
		}


	}
}